with v8.Class_Heap_Snapshot;
with v8.Class_Value, v8.Class_String;
with v8.Class_Activity_Control;
with v8.Class_Retained_Object_Info;
package v8.Class_Heap_Profiler is
   -- Interface for controlling heap profiling.

   type  Wrapper_Info_Callback is access function
     (class_id : uint16_t;
      wrapper : v8.Class_Value.Pointer
     ) return v8.Class_Retained_Object_Info.Pointer;
   -- Callback function invoked for obtaining Retained_Object_Info for
   -- the given JavaScript wrapper object. It is prohibited to enter V8
   -- while the callback is running: only getters on the handle and
   -- Get_Pointer_From_Internal_Field on the objects are allowed.


   function Get_Snapshots_Count return int;
   -- Returns the number of snapshots taken.

   function Get_Snapshot
     (index : int
     ) return v8.Class_Heap_Snapshot.Reanonly_Pointer;
   -- Returns a snapshot by index.

   function Find_Snapshot
     (uid : unsigned
     ) return v8.Class_Heap_Snapshot.Reanonly_Pointer;
   -- Returns a profile by uid.

   function Take_Snapshot
     (title    : v8.Class_String.Pointer;
      the_type : Heap_Snapshot_Type.Enum := Heap_Snapshot_Type.k_Full;
      control  : v8.Class_Activity_Control.Pointer := null
     ) return v8.Class_Heap_Snapshot.Reanonly_Pointer;
   -- Takes a heap snapshot and returns it. Title may be an empty string.
   -- See HeapSnapshot::Type for types description.

   procedure Delete_All_Snapshots;
   -- Deletes all snapshots taken. All previously returned pointers to
   -- snapshots and their contents become invalid after this call.

   procedure Define_Wrapper_Class
     (class_id : uint16_t;
      callback : Wrapper_Info_Callback);
   -- Binds a callback to embedder's class ID.

   k_Persistent_Handle_No_ClassId : aliased constant uint16_t;
   -- v8-profiler.h:429

private

   pragma Convention (CPP, Wrapper_Info_Callback);
   pragma Import (CPP, Get_Snapshots_Count, "_ZN2v812HeapProfiler17GetSnapshotsCountEv");
   pragma Import (CPP, Get_Snapshot, "_ZN2v812HeapProfiler11GetSnapshotEi");
   pragma Import (CPP, Find_Snapshot, "_ZN2v812HeapProfiler12FindSnapshotEj");
   pragma Import (CPP, Take_Snapshot, "_ZN2v812HeapProfiler12TakeSnapshotENS_6HandleINS_6StringEEENS_12HeapSnapshot4TypeEPNS_15ActivityControlE");
   pragma Import (CPP, Delete_All_Snapshots, "_ZN2v812HeapProfiler18DeleteAllSnapshotsEv");
   pragma Import (CPP, Define_Wrapper_Class, "_ZN2v812HeapProfiler18DefineWrapperClassEtPFPNS_18RetainedObjectInfoEtNS_6HandleINS_5ValueEEEE");
   pragma Import (CPP, k_Persistent_Handle_No_ClassId, "_ZN2v812HeapProfiler26kPersistentHandleNoClassIdE");
end v8.Class_Heap_Profiler;
